{% extends "base.html" %}
{% set query_params=request.query_params %}

{% block title %}新写作{% endblock title %}
{% block subtitle %}新写作{% endblock subtitle %}

{% block content %}
<!-- 开始搜索完整的帖子 { -->
<fieldset id="new_sch">
    <legend>搜索详细信息</legend>
    <form name="fnew" method="get">
        <label for="gr_id" class="blind">组</label>
        {{ get_group_select('gr_id', query_params.gr_id)|safe }}

        <label for="view" class="blind">搜索目标</label>
        <select name="view" id="view">
            <option value="">完整的帖子</option>
            <option value="write" {{ get_selected(query_params.view, "write") }}>只有原创写作</option>
            <option value="comment" {{ get_selected(query_params.view, "comment") }}>仅注释</option>
        </select>
        <label for="mb_id" class="blind">搜索词<strong class="blind"> 必不可少的</strong></label>
        <input type="text" name="mb_id" value="{{ query_params.mb_id }}" id="mb_id" class="frm_input" size="40">
        <button type="submit" class="btn_submit">
            <i class="fa fa-search" aria-hidden="true"></i> 搜索
        </button>
        <p>只能搜索成员Idias</p>
    </form>
</fieldset>
<!-- } 完整帖子搜索结束 -->

<!-- 开始完整的帖子列表 { -->
<form name="fnewlist" id="fnewlist" method="post" action="#" onsubmit="return fnew_submit(this);">
    <input type="hidden" name="view" value="{{ query_params.view }}">

    {% if request.state.is_super_admin %}
    <input type="hidden" name="token" value="">

    <div class="admin_new_btn">
        <button type="submit" title="删除所选内容" class="btn_b01 btn">
            <i class="fa fa-regular fa-trash-can" aria-hidden="true"></i>
            <span class="blind">删除所选内容</span>
        </button>
    </div>
    {% endif %}
    <div class="tbl_head01 tbl_wrap">
        <table>
            <thead>
                <tr>
                    {% if request.state.is_super_admin %}
                    <th scope="col" class="chk_box" width="5%">
                        <input type="checkbox" id="all_chk">
                        <label for="all_chk">
                            <span>&nbsp;</span>
                            <b class="blind">完整列表</b>
                        </label>
                    </th>
                    {% endif %}
                    <th scope="col">组</th>
                    <th scope="col">公告板</th>
                    <th scope="col">标题</th>
                    <th scope="col">姓名</th>
                    <th scope="col">临时</th>
                </tr>
            </thead>
            <tbody>
                {% for board_new in board_news %}
                <tr>
                    {% if request.state.is_super_admin %}
                    <td class="td_chk chk_box">
                        <input type="checkbox" name="chk_bn_id[]" value="{{ board_new.bn_id }}" id="chk_bn_id_{{ loop.index }}">
                        <label for="chk_bn_id_{{ loop.index }}">
                            <span>&nbsp;</span>
                            <b class="blind">{{ board_new.num }}烧伤</b>
                        </label>
                    </td>
                    {% endif %}
                    <td class="td_group">
                        <a href="/bbs/new?gr_id={{ board_new.board.gr_id }}">{{ board_new.board.group.gr_subject }}</a>
                    </td>
                    <td class="td_board">
                        <a href="/board/{{ board_new.bo_table }}">{{ board_new.board.bo_subject }}</a>
                    </td>
                    <td>
                        <a href="{{ board_new.link }}" class="new_tit">{{ board_new.subject }}</a>
                    </td>
                    <td class="td_name">{{ board_new.name }}</td>
                    <td class="td_date">{{ board_new.datetime }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    {{ paging|safe }}

    {% if request.state.is_super_admin %}
    <div class="admin_new_btn">
        <button type="submit" title="删除所选内容" class="btn_b01 btn">
            <i class="fa fa-regular fa-trash-can" aria-hidden="true"></i>
            <span class="blind">删除所选内容</span>
        </button>
    </div>
    {% endif %}
</form>

{% if request.state.is_super_admin %}
<script>
    $(function(){
        $('#all_chk').click(function(){
            $('[name="chk_bn_id[]"]').attr('checked', this.checked);
        });
    });

    function fnew_submit(f)
    {
        var cnt = 0;
        for (var i =0; i < f.length; i++) {
            if (f.elements[i].name == "chk_bn_id[]" && f.elements[i].checked)
                cnt++;
        }

        if (!cnt) {
            alert("选择一个或多个要删除的帖子.");
            return false;
        }

        if (!confirm("是否确实要删除所选帖子?\n\n您无法恢复一次删除的材料")) {
            return false;
        }

        f.token.value = generate_token();
        f.action = "./new_delete?{{ query_params|safe }}";

        return true;
    }
</script>
{% endif %}
{% endblock content %}